package org.kl.bpm.entity.conf;

import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.kl.bf.entity.AuditableEntity;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 
 * @Author hqm
 * @CreateTime 2014年5月25日 下午8:05:24
 * @Mender chb
 * @ChangeTime 2014年12月17日 
 * 添加流程发起人流程发起时间字段
 * 流程KV变量记录表
 */
@Entity
@Table(name = "bpm_kv_record")
public class BpmKvRecord extends AuditableEntity {
	private static final long serialVersionUID = 2472048897408899563L;
	/**
	 * BpmProcess ID
	 */
	private String category;
	/**
	 * 0：流程草稿 1：任务草稿 2：执行中
	 */
	private int status;
	/**
	 * 流程实例ID
	 */
	private String ref;
	/**
	 * 流程发起人
	 */
	private String processCreate;
	/**
	 * 流程发起时间
	 */
	private Date processTime;
	/**
	 * 业务ID（如果不是外部业务则为空）
	 */
	private String businessId;
	private Set<BpmKvProp> bpmKvProps = new HashSet<BpmKvProp>(0);

	private Map<String, BpmKvProp> props = new LinkedHashMap<String, BpmKvProp>();

	@Column(name = "record_category", length = 200)
	public String getCategory() {
		return category;
	}

	public void setCategory(String category) {
		this.category = category;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getRef() {
		return ref;
	}

	public void setRef(String ref) {
		this.ref = ref;
	}

	@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "bpmKvRecord")
	public Set<BpmKvProp> getBpmKvProps() {
		return bpmKvProps;
	}

	public void setBpmKvProps(Set<BpmKvProp> bpmKvProps) {
		this.bpmKvProps = bpmKvProps;
	}

	public String getBusinessId() {
		return businessId;
	}

	public void setBusinessId(String businessId) {
		this.businessId = businessId;
	}

	@Transient
	public Map<String, BpmKvProp> getProps() {
		Map<String, String> map = new HashMap<String, String>();
		for (BpmKvProp prop : this.getBpmKvProps()) {
			map.put(prop.getCode(), prop.getValue());
		}
		return props;
	}

	public void setProps(Map<String, BpmKvProp> props) {
		this.props = props;
	}

	public String getProcessCreate() {
		return processCreate;
	}

	public void setProcessCreate(String processCreate) {
		this.processCreate = processCreate;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getProcessTime() {
		return processTime;
	}

	public void setProcessTime(Date processTime) {
		this.processTime = processTime;
	}

}
